import pymysql
import cy_config
import cy_log

db = pymysql.connect(
    host='',
    user='',
    password='',
    database='',
    port=3306
)

# 上传盈利信息
def insertYinliData(open_price, pingc_price, trad_time, yinli, side, executedQty):

    try:
        cursor = db.cursor()
        db.ping()

        if open_price:
            pass
        else:
            open_price = ''
        
        if pingc_price:
            pass
        else:
            pingc_price = ''
        
        if trad_time:
            pass
        else:
            trad_time = ''
        
        if yinli:
            pass
        else:
            yinli = ''
        
        if side:
            pass
        else:
            side = ''

        if executedQty:
            pass
        else:
            executedQty = ''

        sql = "insert into fa_wange_infos(user_id, open_price, pingc_price, trad_time, yinli, side, symbol) values(%s, %s, %s, %s, %s, %s, %s)"
        cursor.execute(sql, (cy_config.user_id, open_price, pingc_price, trad_time, yinli, side, cy_config.symbol))

        db.commit() # 提交语句
        db.close()

    except Exception as e:
        cy_log.printAndInLog('=========== 报错 ============')
        cy_log.printAndInLog('上传服务器报错：' + str(e))
        cy_log.printAndInLog('=========== 报错 ============')
    else:
        pass
